class EventBind {
  constructor() {
    this.callbacks = [];
    setTimeout(() => {
      this.next();
    }, 0);
  }

  play() {
    this.callbacks.push(() => {
      console.log("play");
      this.next();
    });
    return this;
  }

  sleep() {
    this.callbacks.push(() => {
      setTimeout(() => {
        console.log("sleep");
        this.next();
      }, 1000);
    });
    return this;
  }

  next() {
    const event = this.callbacks.shift();
    event && event();
  }
}

const event1 = new EventBind();
event1.sleep().play();
